package com.water.app.Controller.Goods;

import com.water.app.Goods;
import com.water.app.Type;
import com.water.app.interfaces.Goods.GoodsService;
import com.water.app.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Set;

@RestController
@RequestMapping("/api/Goods")
public class GoodsController {

    private static final Logger log = LoggerFactory.getLogger(GoodsController.class);
    @Autowired
    private GoodsService goodsService;
    @GetMapping("/selectAll")
    public Result selectAll(){
        Set<Goods> set= goodsService.SelectAllGoods();
        return Result.success(set);
    }



    @GetMapping("/sKill")
    public Result sKill(){
        return goodsService.selectSKill();
    }

    //查询商品全部分类
    @GetMapping("/selectByAllType")
    public Result  selectByType(){
        List<String> list = goodsService.selectByAllType();
        return Result.success(list);
    }

    //模糊搜索商品
    @GetMapping("/likeSelect")
    public Result selectByLike(String likeName){

        List<Goods> goods = goodsService.selectByLike(likeName);
        return Result.success(goods);
    }

    @GetMapping("/sort")
    public Result selectBySort(){
        List<Goods> list= goodsService.selectBySort();
        return Result.success(list);

    }

    //按种类查询商品
    @GetMapping("/selectByType/{type}")
    public Result selectByType(@PathVariable("type") Integer type){
        List<Goods> list= goodsService.selectByType(type);
        return Result.success(list);
    }
    @GetMapping("/idSelect")
    public Result selectById(int id){
        Goods goods = goodsService.selectById(id);
        return Result.success(goods);
    }

    @GetMapping("/selectAllType")
    public Result selectAllType(){
        log.info("正在查询商品种类");
        List<Type> typeList= goodsService.selectAllType();
        return Result.success(typeList);
    }


    @GetMapping("/{goodsId}")
    public Result selectGoods(@PathVariable int goodsId){
        log.info("goodsId:{}",goodsId);
        Goods goods=goodsService.selectById(goodsId);
        goods.setId(goodsId);
        if(goods!=null) {
            log.info("查询商品信息成功");
            log.info("goodsId111:{}",goods.getId());
            log.info("goods:{}",goods);
            return Result.success(goods);
        }else {
            log.info("查询商品信息失败");
            return Result.error(0,"查询商品信息失败!",null);
        }
    }






}

